package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_server.gradesub_server;

import com.alibaba.fastjson.JSON;

@WebServlet("/gradesub")
public class gradesub_servlet extends HttpServlet
{
	gradesub_server	gs	= new gradesub_server();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		PrintWriter pw = resp.getWriter();
		String code = req.getParameter("code");
		try
		{
			if (code.equals("0"))
			{
				String json = JSON.toJSONString(gs.show_subject());
				pw.write(json);
			} else
			{
				int key = Integer.parseInt(req.getParameter("key"));
				boolean isok = gs.delsubject(key);
				pw.write(isok + "");

			}
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

}
